package com.vichat.common.threads;
import com.vichat.common.constant.GlobalConstant;
import com.vichat.common.signal.CmdUtil;
import com.vichat.common.vo.SysMsg;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;

/**
 * Created by ranjx on 2018/03/13.
 */
public class SysMsgThread implements Runnable{
    private static Logger logger = LoggerFactory.getLogger(SysMsgThread.class);
    private List<SysMsg> sysMsgs = null;

    public SysMsgThread(List<SysMsg> sysMsgs) {
        this.sysMsgs = sysMsgs;
    }

    @Override
    public void run() {
        try {
            if(!sysMsgs.isEmpty()){
                for (SysMsg msg : sysMsgs) {
                    //IM通知消息
                    if(msg.getCmdType().equals(GlobalConstant.IMS_EVENT_QUEUE)) {
                        CmdUtil.sendImMsg(msg.getSndId(), msg.getRcvId(), 0, msg.getMsgType(), msg.getMsg());
                    }
                    //房间通知消息
                    if(msg.getCmdType().equals(GlobalConstant.GMS_EVENT_QUEUE)) {
                        CmdUtil.sendRoomMsg(msg.getSndId(), msg.getRcvId(), msg.getRid(), msg.getMsgType(), msg.getMsg());
                    }
                }
            }
        } catch (Exception e) {
            logger.error("发送消息失败>>>>>>" + e.getMessage(), e);
        }
    }

}
